import {ActionType, PageContainer, ProColumns, ProTable} from "@ant-design/pro-components";
import React, {useRef} from "react";
import {globalLoadTableApiCode} from "@/services/admin-api/globalApi";
import {paySource, payType} from "@/pages/Order/Management";
import {useAccess} from "umi";

type PayRecord = {
  payId: number;
  orderId: number;
  payMoney: number;
  payType: number;
  paySource: number;
  payRemark: string;
  payAfterDeposit: number;
  payBeforeDeposit: number;
  payAfterFinalPayment: number;
  payBeforeFinalPayment: boolean;
  payAfterTotalPrice: boolean;
  payBeforeTotalPrice: boolean;
  douyinCode: string;
  douyinCodeStatus: number;
  delFlag: boolean;
  createTime: string;
  createUserId: number;
  createUserName: string;
  updateTime: string;
  updateUserId: number;
  updateUserName: string;
};

export default () => {
  const access = useAccess()

  const actionRef = useRef<ActionType>();

  const columns: ProColumns<PayRecord>[] = [
    {title: 'ID', dataIndex: 'payId', valueType: 'digit', hideInSearch: true},
    {title: '订单ID', dataIndex: 'orderId', valueType: 'text', copyable: true},
    {title: '金额', dataIndex: 'payMoney', valueType: 'money', hideInSearch: true},
    {
      title: '支付类型',
      dataIndex: 'payType',
      valueType: 'select',
      fieldProps: {options: payType.data},
    },
    {
      title: '支付渠道',
      dataIndex: 'paySource',
      valueType: 'select',
      fieldProps: {options: paySource.data},
    },
    {title: '抖音券码', dataIndex: 'douyinCode', valueType: 'text',},
    {
      title: '券码状态',
      dataIndex: 'douyinCodeStatus',
      valueType: 'select',
      fieldProps: {options: [{label: '已核销', value: 0}, {label: '退核销', value: 1}]}
    },
    {title: '备注', dataIndex: 'payRemark', valueType: 'text', hideInSearch: true},
    {title: '定金(前)', dataIndex: 'payBeforeDeposit', valueType: 'money', hideInSearch: true},
    {title: '定金(后)', dataIndex: 'payAfterDeposit', valueType: 'money', hideInSearch: true},
    {title: '尾款(前)', dataIndex: 'payBeforeFinalPayment', valueType: 'money', hideInSearch: true},
    {title: '尾款(后)', dataIndex: 'payAfterFinalPayment', valueType: 'money', hideInSearch: true},
    {title: '总价(前)', dataIndex: 'payBeforeTotalPrice', valueType: 'money', hideInSearch: true},
    {title: '总价(后)', dataIndex: 'payAfterTotalPrice', valueType: 'money', hideInSearch: true},
    {title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', hideInSearch: true,},
    {title: '创建用户ID', dataIndex: 'createUserId', valueType: 'digit', hideInSearch: true,},
    {title: '创建用户', dataIndex: 'createUserName', valueType: 'text', hideInSearch: true,},
    {title: '更新时间', dataIndex: 'updateTime', valueType: 'dateTime', hideInSearch: true,},
    {title: '更新用户ID', dataIndex: 'updateUserId', valueType: 'digit', hideInSearch: true,},
    {title: '更新用户', dataIndex: 'updateUserName', valueType: 'text', hideInSearch: true,},
    // {
    //   title: <SettingFilled/>,
    //   render: (_, record) => [
    //     record.douyinCodeStatus === 0 ?
    //       <Tooltip title={"取消验券"} key={`cancen_${record.payId}`}>
    //         <Popconfirm
    //           title="取消验券"
    //           description="确认取消此支付记录的验券？"
    //           onConfirm={async () => {
    //             await handleGloblApi('/order/cancelDouyin', {payId: record.payId});
    //             actionRef.current?.reload()
    //           }}
    //           onCancel={() => {
    //           }}
    //           okText="确认"
    //           cancelText="不确认"
    //         >
    //           <Button size={"small"} danger>Delete</Button>
    //         </Popconfirm>
    //       </Tooltip> : '',
    //   ],
    //   valueType: 'option',
    // },
  ];

  return <PageContainer header={{title: '', breadcrumb: {},}}>
    <ProTable<PayRecord>
      columns={columns} actionRef={actionRef}
      search={{span: 4}}
      // headerTitle={
      //   <Button
      //     key="primary" type="primary" icon={<PlusOutlined/>} onClick={() => {
      //     handleModalOpen(true)
      //   }}/>
      // }
      request={async (param) => globalLoadTableApiCode('/payRecord/table', 'pay:list:search', access, param)}
      rowKey={(record) => record.payId}
      columnsState={{
        defaultValue: {
          delFlag: {show: false},
          createUserId: {show: false},
          updateUserId: {show: false}
        }
      }}/>

  </PageContainer>
}
